﻿@{
    ViewBag.Title = "选择角色";
    Layout = "~/Views/Shared/_LightLayout.cshtml";
}
<div class="row  border-bottom white-bg dashboard-header">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>请选择角色</h5> <span class="label label-primary"></span>
                    <a class="btn btn-primary pull-right" id="btnOk"><i class="fa fa-check"></i> 确定选择</a>
                </div>
                <div class="ibox-content icons-box">
                    <div id="jstree_menu" class="demo" style="margin-top:1em; min-height:200px;"></div>
                </div>
            </div>
        </div>
    </div>
    <p style="margin-top:20px"></p>
</div>
@section Styles{
    @Styles.Render("~/Content/plugins/jsTree/styles")
}
@section scripts{
    @Scripts.Render("~/plugins/jsTree")
    <script>
        $(function () {
            var jtree = $('#jstree_menu').jstree({
                "core": {
                    "animation": 0,
                    "check_callback": true,
                    'force_text': true,
                    "themes": { "stripes": true },
                    'data': {
                        'url': function (node) {
                            return '/SystemAdmin/AppUsers/GetRoles?userId=@ViewBag.UserId&t=' + new Date().getTime();
                        },
                        'data': function (node) {
                            return { 'id': node.id };
                        }
                    }
                },
                "types": {
                    "#": { "icon": "fa fa-folder" },
                    "root": { "icon": "fa fa-folder" },
                    "default": { "icon": "fa fa-th-large" }
                },
                "plugins": ["types", "checkbox"]
            });
            $('#btnOk').on('click', function () {
                var checks = $('#jstree_menu').jstree('get_checked');
                console.debug(checks);
                if (checks.length == 0) {
                    mwc.message.error('请选择角色！');
                    return;
                }
                if (window.parent != window.self) {
                    mwc.restApi.post({
                        url: '@Url.Action("SetRoles")',
                        data: {userId:'@ViewBag.UserId', roleIds: checks },
                        success: function (resData) {
                            if (resData.Success) {
                                mwc.window.closeSeft();
                            }
                        }
                    });
                }
            });
        });

    </script>
}